<template>
	<view>
		<custom-nav-sq-xcx :isBack="true" currBg="usuallyBg" :needConBlock="true">
			<block slot="content">乡镇列表</block>
		</custom-nav-sq-xcx>
		<view class="sqConBlock"></view>
		<view class="sqConWrap">
			<view class="gridList"
				:class="[currIndex == index ? 'active' : '']"
				v-for="(item,index) in townList"
				:key="index"
				@tap="selCurrTown(index,item.townName)"
			>{{item.townName}}</view>
		</view>
	</view>
</template>

<script>
	//import { getTownData } from '@/api/sqSys/getArea.js'
	export default {
		data(){
			return{
				countyCode:'',
				townList:[],
				currIndex:-1,
				townName:'',
				isHasDataFlag:null
			}
		},
		onLoad(option){
			this.countyCode = option.countyCode;
			this.townName = option.townName;
			//this.loadTownList();
		},
		methods:{
			loadTownList(){
				let field = { countyCode:this.countyCode }
				getTownData(field).then(res=>{
					this.isHasDataFlag = true;
					this.townList = res.data.datas;
					if(this.townName != ''){
						for(let i in this.townList){
							if(this.townList[i].townName == this.townName){
								this.currIndex = Number(i);
							}
						}
					}
				}).catch(err=>{
					this.isHasDataFlag = false;
					console.log(err)
				});
			},
			selCurrTown(index,townName){
				this.currIndex = index;
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				prevPage.$vm.townName = townName;
				prevPage.$vm.selTownFlag = true;
				prevPage.$vm.groupId = 0;
				prevPage.$vm.gridName = '请选择负责网格';
				prevPage.$vm.selGridFlag = false;
				uni.navigateBack({delta:1})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: $sq-fuf;
	}
</style>
<style lang="scss" scoped>
	.gridList{
		height: 90rpx;
		line-height: 90rpx;
		font-size: 28rpx;
		padding:0 30rpx;
		background: #fff;
		color: $sq-main0;
		border-bottom: 1rpx solid #eee;
		&:nth-of-type(2n){
			background: $sq-fuf;
		}
		&.active{
			color: $pss-sq-main;
			font-weight: 600;
		}
		&:last-child{
			border-bottom: none;
		}
	}
	
</style>